// @(#)db.hh
// Time-stamp: <2009-01-13 23:37:35 root>
// Copyright 2008 Julian Qian
// Author: root@localhost.localdomain
// Version: $Id: db.hh,v 0.0 2008/11/16 20:00:14 root Exp $
// Keywords: 
//

#ifndef _DB_H
#define _DB_H 1


#include "common.hh"

#include <mysql++/mysql++.h>

#define CONN mysqlpp::Connection
#define QUER mysqlpp::Query
#define SIMR mysqlpp::SimpleResult
#define STOR mysqlpp::StoreQueryResult

#define DB_CONF_LEN  20
#define CONN_USE_MAX 100

class Db: public mysqlpp::ConnectionPool {
public:
    // static Db* theDb();
    // static void endDb();
    CONN * con();
    void end(CONN*);
    Db();
    virtual ~Db();

private:

    CONN* create();
    void destroy(CONN* con);
    unsigned int max_idle_time();
    // static Db* _theDb;

    unsigned int conns_in_use_;

    char database[DB_CONF_LEN];
    char hostname[DB_CONF_LEN];
    char username[DB_CONF_LEN];
    char password[DB_CONF_LEN];    
};

#endif /* _DB_H */

